package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
//@Component
public class AspectDemo {
    @Pointcut("execution(* com.example.aop.controller.*.*(..))")
    public void pt(){};

    @Before("pt()")
    public void doBefore() {
        log.info("AspectDemo do before....");
    }

    @After("pt()")
    public void doAfter() {
        log.info("AspectDemo do after....");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("AspectDemo do around before....");
        Object result = joinPoint.proceed();
        log.info("AspectDemo do around after....");
        return result;
    }

    @AfterReturning("execution(* com.example.aop.controller.*.*(..))")
    public void doAfterReturning() {
        log.info("AspectDemo do after return....");
    }

    @AfterThrowing("execution(* com.example.aop.controller.*.*(..))")
    public void doAfterThrowing() {
        log.info("AspectDemo do after throwing....");
    }
}
